# Contributor: Stefan Reiff <kroko87@hotmail.com>
# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer: Taner Tas <taner76@gmail.com>
pkgname=vdr
pkgver=2.4.4
pkgrel=0
pkgdesc="Video Disk Recorder"
url="http://www.tvdr.de/"
arch="all"
license="GPL-2.0-or-later"
depends_dev="libexecinfo-dev fontconfig-dev freetype-dev gettext-dev libjpeg-turbo-dev fribidi-dev
	libcap-dev alsa-lib-dev libvdpau-dev libva-dev libx11-dev xcb-util-dev xcb-util-wm-dev
	ffmpeg-dev libcdio-dev mpv-dev libdvbcsa-dev ncurses-dev libwebsockets-dev libexif-dev
	jansson-dev openssl-dev tinyxml2-dev"
makedepends="$depends_dev bash coreutils groff perl util-linux"
install="$pkgname.pre-install"
pkgusers="$pkgname"
pkggroups="$pkgname"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-openrc
	$pkgname-femon
	$pkgname-mpv
	$pkgname-epgsearch
	$pkgname-streamdev
	$pkgname-vnsiserver
	$pkgname-dvbapi
	$pkgname-svdrpservice
	$pkgname-vdrmanager
	$pkgname-skincurses
	$pkgname-osd2web"
#no testsuite available
options="!check"

_femon_ver=d366856c719874ddf13886a00d741c4faa14130c
_mpv_ver=87543f7058b88a3ace8550551bb3982cc304720e
_vnsiserver_ver=a06ad5fbd4f5d2d547a17db291178d113dfbc699
_streamdev_ver=e2a9b979d3fb92967c7a6a8221e674eb7e55c813
_epgsearch_ver=d8cff1a251ef2b54f1de3f8e6ea55a838eeb73c3
_dvbapi_ver=197e7524e563923d4b86e74a121f7174373818d9
_svdrpservice_ver=1.0.0
_vdrmanager_ver=0398f105bcc166d2695f3b8b2f91327c04acca48
_osd2web_ver=0.2.52

_confd_dir=etc/vdr/conf.d
_plugins_conf_dir=etc/vdr/plugins

source="ftp://ftp.tvdr.de/vdr/vdr-$pkgver.tar.bz2
	$pkgname.initd
	conf.d/00-vdr.conf
	vdr-plugin-femon-$_femon_ver.tar.gz::https://github.com/rofafor/vdr-plugin-femon/archive/$_femon_ver.tar.gz
	conf.d/femon.conf
	vdr-plugin-mpv-$_mpv_ver.tar.gz::https://github.com/chriszero/vdr-plugin-mpv/archive/$_mpv_ver.tar.gz
	conf.d/mpv.conf
	vdr-plugin-vnsiserver-$_vnsiserver_ver.tar.gz::https://github.com/FernetMenta/vdr-plugin-vnsiserver/archive/$_vnsiserver_ver.tar.gz
	conf.d/vnsiserver.conf
	vdr-plugin-streamdev-$_streamdev_ver.tar.gz::https://projects.vdr-developer.org/git/vdr-plugin-streamdev.git/snapshot/vdr-plugin-streamdev-$_streamdev_ver.tar.gz
	conf.d/streamdev-server.conf
	vdr-plugin-epgsearch-$_epgsearch_ver.tar.gz::https://projects.vdr-developer.org/git/vdr-plugin-epgsearch.git/snapshot/vdr-plugin-epgsearch-$_epgsearch_ver.tar.gz
	conf.d/conflictcheckonly.conf
	conf.d/epgsearch.conf
	conf.d/epgsearchonly.conf
	conf.d/quickepgsearch.conf
	vdr-plugin-dvbapi-$_dvbapi_ver.tar.gz::https://github.com/manio/vdr-plugin-dvbapi/archive/$_dvbapi_ver.tar.gz
	conf.d/dvbapi.conf
	vdr-plugin-svdrpservice-$_svdrpservice_ver.tar.gz::https://vdr.schmirler.de/svdrpservice/vdr-svdrpservice-$_svdrpservice_ver.tgz
	conf.d/svdrpservice.conf
	vdr-plugin-vdrmanager--$_vdrmanager_ver.tar.gz::https://projects.vdr-developer.org/git/vdr-manager.git/snapshot/vdr-manager-$_vdrmanager_ver.tar.gz
	vdr-plugin-osd2web-$_osd2web_ver.tar.gz::https://github.com/horchi/vdr-plugin-osd2web/archive/$_osd2web_ver.tar.gz
	conf.d/osd2web.conf
	musl-compat.patch
	Make.config
	include-missing-limits.patch
	streamdev_makefile.patch
	osd2web.patch"

prepare() {
	cp -aP $srcdir/vdr-plugin-femon-${_femon_ver} $builddir/PLUGINS/src/femon
	cp -aP $srcdir/vdr-plugin-mpv-${_mpv_ver} $builddir/PLUGINS/src/mpv
	cp -aP $srcdir/vdr-plugin-vnsiserver-${_vnsiserver_ver} $builddir/PLUGINS/src/vnsiserver
	cp -aP $srcdir/vdr-plugin-streamdev-${_streamdev_ver} $builddir/PLUGINS/src/streamdev
	cp -aP $srcdir/vdr-plugin-epgsearch-${_epgsearch_ver} $builddir/PLUGINS/src/epgsearch
	cp -aP $srcdir/vdr-plugin-dvbapi-${_dvbapi_ver} $builddir/PLUGINS/src/dvbapi
	cp -aP $srcdir/svdrpservice-${_svdrpservice_ver} $builddir/PLUGINS/src/svdrpservice
	cp -aP $srcdir/vdr-manager-$_vdrmanager_ver/vdr-vdrmanager $builddir/PLUGINS/src/vdrmanager
	cp -aP $srcdir/vdr-plugin-osd2web-$_osd2web_ver $builddir/PLUGINS/src/osd2web
	default_prepare
}

build() {
	cp $srcdir/Make.config $builddir
	case "$CARCH" in
		x86*) make ;;
		*) make LIBDVBCSA=1 ;;
	esac
}

femon() {
	_plugin_defaults femon
}

mpv() {
	_plugin_defaults mpv
}

vnsiserver() {
	_plugin_defaults vnsiserver
	mkdir -p $subpkgdir/$_plugins_conf_dir
	cp -a $builddir/PLUGINS/src/vnsiserver/vnsiserver $subpkgdir/$_plugins_conf_dir
}

streamdev() {
	_plugin_defaults streamdev-client streamdev-server
	mkdir -p $subpkgdir/$_plugins_conf_dir
	cp -a $builddir/PLUGINS/src/streamdev/streamdev-server $subpkgdir/$_plugins_conf_dir
}

epgsearch() {
	_plugin_defaults conflictcheckonly epgsearch epgsearchonly quickepgsearch
	mkdir -p $subpkgdir/$_plugins_conf_dir
	mv $_plugins_conf_dir/epgsearch $subpkgdir/$_plugins_conf_dir
}

dvbapi() {
	_plugin_defaults dvbapi
}

svdrpservice() {
	_plugin_defaults svdrpservice
}

vdrmanager() {
	_plugin_defaults vdrmanager
	mkdir -p $subpkgdir/$_confd_dir
	sed '1s/^/[vdrmanager]\n/' $srcdir/vdr-manager-$_vdrmanager_ver/vdr-vdrmanager/examples/plugin.vdrmanager.conf \
		> $subpkgdir/$_confd_dir/vdrmanager.conf
}

osd2web() {
	_plugin_defaults osd2web
	mkdir -p $subpkgdir/$_confd_dir
	mkdir -p $subpkgdir/$_plugins_conf_dir
	mv $_plugins_conf_dir/osd2web $subpkgdir/$_plugins_conf_dir
}

skincurses() {
	_plugin_defaults skincurses
}

package() {
	case "$CARCH" in
		x86*) make -j1 DESTDIR="$pkgdir" install ;;
		*) make -j1 LIBDVBCSA=1 DESTDIR="$pkgdir" install ;;
	esac
	install -D -m755 "$srcdir"/$pkgname.initd \
		$pkgdir/etc/init.d/$pkgname
	install -m644 $srcdir/00-vdr.conf \
		$pkgdir/$_confd_dir/00-vdr.conf
	chown -R $pkgusers:$pkggroups $pkgdir/etc/vdr \
		$pkgdir/var/cache/vdr $pkgdir/var/lib/vdr/video
}

_plugin_defaults() {
	depends="${pkgname}=$pkgver-r$pkgrel"
	cd "$pkgdir"
	mkdir -p $subpkgdir/usr/lib/vdr
	local plugin_name
	for plugin_name in "$@"; do
		[ -f $srcdir/$plugin_name.conf ] && \
			install -D -m644 $srcdir/$plugin_name.conf \
				$subpkgdir/$_confd_dir/$plugin_name.conf
		[ -f usr/lib/vdr/libvdr-$plugin_name.so.* ] && \
			mv usr/lib/vdr/libvdr-$plugin_name.so.* \
				$subpkgdir/usr/lib/vdr
	done
}

sha512sums="52a9047e2fdfbf80f1ee9b4c5d1bd414bc05632147e82e0ee0f25eb9bca03e52a0e73d3fdf7debfad6712e7dc124fe40a09a8d1663deabcd3745ed7c51b2449f  vdr-2.4.4.tar.bz2
52a6221096f543d7af76f14d1e9227bd9a84151eb1c41654c048f5fcb95759e4d98639ba84921c3306742815f4ee3ba8f93ac1799215cfb1a19370b84f80041f  vdr.initd
43502a337324910c8f5db71097336b55a7a58629f201f3a5032397e406ddaf631c647f64220241a84b2eb1b2e0e85af05fa1b017d3d05732c643a754455609d2  00-vdr.conf
741c84ef3769e7b101288315cbbed7c9e9c047b382f888e9789e40c7a6ee734028a41aff03fc0d688a9e5b9091ea2f33896adb6b5ec47f21ff09e29f860500c1  vdr-plugin-femon-d366856c719874ddf13886a00d741c4faa14130c.tar.gz
c80295dd6b4d27eed0639131e104bd071ea3ff55503fc5fdbed4e7668221775a062d37d9e4ff322e4cdc554f0f4ba29adbe3f6424504a74c93f5d302f8f0a904  femon.conf
a9047da75cc11e675123d418c15a9712ac019658836630c7949699e39a0ade555dd2d52845abffd2cce0857e2c810f4bb5a7bf8b80dbc1a3c1b75002392dece3  vdr-plugin-mpv-87543f7058b88a3ace8550551bb3982cc304720e.tar.gz
c3663b890af2be949e4faffac1ccc1064bb377aa3ba85b4d136ce71db3a1c49b01e9c327e13cd5d02c3d0d850677c3f97a42628957738c17a74d04ec86950bdf  mpv.conf
b8f8611834c21c101b5c48ed65fdf6867025c60a53560c1fac3bb2ef43b286692a14d34926e9715d9894a3b320b99046331e8d1c4aab0f44c53604f2520a2808  vdr-plugin-vnsiserver-a06ad5fbd4f5d2d547a17db291178d113dfbc699.tar.gz
f5672a2929c1ba177a8223dd071b5968bd0fa3f56ac9e0a267dc596adf8884262c239c53e482d3f7c278ce8adaccbb6a179fde704f77160e3a13e8d0a64904b4  vnsiserver.conf
4bd1cb3115ec6d9e91b1ff38f761fb7cd95d314f96ec00e619a993afc8422f2dc5b30f2638e9fbf27afe20fbd9597318aa8e347efca29d4cabeff7e2e4f3c25c  vdr-plugin-streamdev-e2a9b979d3fb92967c7a6a8221e674eb7e55c813.tar.gz
f1aabdb5ab3f9032419dd9cb60bd48402a0f034fb01f7ade2b625cb505719175f245036fae3699f1d0314f48819919e6f7cb48de73d9acf4ef43114504223f48  streamdev-server.conf
586b369a25c32bbf2d33e68997e7298ad7fda50ac78da5321c848a74d91753a51e6f47d70ef6893ca980bfa2c9f167defd611464729ca4ebf704247e8e37a065  vdr-plugin-epgsearch-d8cff1a251ef2b54f1de3f8e6ea55a838eeb73c3.tar.gz
770c06cd1769da932f2a962cae29e4158992e2510c9e29b7b9cf9e1dccccefcd1b60e22001c60ba6bc05f25ec2a050a8f5299d52f9920bb50ed976a9a8460150  conflictcheckonly.conf
d3046f1a4dd2b2e1166cae05160be835998826f6aa055fc6d53ee81a1f39a7d6297ed23290056dbf51e054fe6b124c52d539b88064c539b8662dba7a780571fa  epgsearch.conf
7b343b0437783bcc6fe6ab1fd46561855c7b84d9886d2a339622635461831e9db08ebf4f7a5f596e937671fd9cad8e2d3952f61dd438f12f08604698a78f43b8  epgsearchonly.conf
f9c1cc50297b5210aa31b92b17769d4afe20ca0f9f15e190f6e34033b1e2c89a37e332e9f2e9fe4b18e98cc3f4558e3175b59b6b33253fe914bcee689656ed7d  quickepgsearch.conf
10a2b17d0f09b1179cb750f694153a035e915087b20df0333374e85f4fa6b1c6406a0105692d9af796f25b502fce57eb955323a032d952000b5bd1236b671f90  vdr-plugin-dvbapi-197e7524e563923d4b86e74a121f7174373818d9.tar.gz
7cdf36a2b6b3c470a1117f057bf233de57d395a899fc98f7941f526bbaf6935f4d5a368b4936db26217c1e39afb30cfdbec889aa4078109e3fa53e776f07d3b9  dvbapi.conf
2395aed428a072b568ed790e0ee8b3e1d17be62fb28a21bc030c021cef778ba00d7e17451eccf26f09da63c8d5b7786fd12e377d904b23ca1b24c040dc5ce429  vdr-plugin-svdrpservice-1.0.0.tar.gz
9cffb3d8347cfc1028bf39a3b14202ea0bc85d7944a7b12863998abca55d113c36ad327c159bc56d1f58bbe9c43c7beae2bf5b21ffbab70a5bc6c632b8b7c4eb  svdrpservice.conf
4d6592c3573f2b786bf8995648b4d4eee5c1658cf1faf1479de52264ea2c38f148bb6ca09ee47bcecdc4470dcea740d154917fe30dba62f14ab49af45573dd36  vdr-plugin-vdrmanager--0398f105bcc166d2695f3b8b2f91327c04acca48.tar.gz
a0ce4485eafd2c9e4694aa79c5875dc797ab669e6be50e511c982f63f7d20fb5b2adf0cde99e9bc1cfe9fded83c88672f4a919e31c9a55698584e3e3bb17f09d  vdr-plugin-osd2web-0.2.52.tar.gz
0a31a07399e37516343d9b3b9b4d6984b91ed34c437dae9ee3377417b601f30f344714ee4965616019be1defccbfc3629a1bea89851fa0c28987674c29796936  osd2web.conf
f47461445515e44f5cdb9c6d3b1bcae323bb83ba3de7c77a3be4d9ac99ed9e76ebe2ee720660c5593fa4b6995366b9d98bf1683f7b8786518a444de7754731ca  musl-compat.patch
6b7102f609bf0272159753dca3b019482e97053a69a666fa0658f45d9d6dbd406070ac9320d127920c2e6d9b32f90b8b47d50d8490b3ce8575830938bb6b84e0  Make.config
7715ef27c820d9e7964dcc24dd12288f66fdf0a6db34d0da43cf6f16e2f815f23bd714654ffa9c3b7d28854bd1e0f7f201dcc5320f99556be92dd248b73bb86f  include-missing-limits.patch
d65877bb0b2e983cf7b1c4b9e3ed8e4105c25f6ef4bb3c400255f4a30f7e177aa41d7a89871e2c4e2afae1447d6bbe26e79105d5ca20b8593ea49c35ae048952  streamdev_makefile.patch
76eb4074a4a811da458e5ecf855925d295718228c9467c633054c3c6751494af3e06113a549f212f398485f947fb3a283fafe34c198967ab4e2d5c1bf5419495  osd2web.patch"
